$(function() {
	layui.use(['form', "laydate", "layer"], function() {
		var form=layui.form;
		var layer = layui.layer;
		var laydate=layui.laydate;
		form.render(); 
		//重新加载date空间
		laydate.render({
			elem: "#birthday", //绑定文本框的id
			type: "date" //时间类型，年月日，时分秒
		});
		//截取地址栏中的字符串
		function GetQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if(r != null) return unescape(r[2]);
			return null;
		}
		var userId=GetQueryString("userId");
		console.log(userId);
		//通过用户ID查询用户要求
		function find_userInfo_ByUserId(userId){
			$.ajax({
				type:"get",
				url:"http://localhost:8080/ssmService/sysUser/selectUserVoByUserId/"+userId,
				async:true,
				"success": function(result) {
					if(result.resultCode == 0) {
						build_userInfo(result);
					} else {
						layer.msg(result.message, {
							icon: 2,
							time: 1000
						});
					}

				}
			});
		}
		function build_userInfo(result){
			var data=result.data;
			if(data.user.head_img_url!=""){
				$("#showImg").attr("src",data.user.head_img_url);
			}
			$("input[name='user.account']").val(data.user.account);
			$("input[name='user.name']").val(data.user.name);
			$("input[name='user.phone']").val(data.user.phone);
			$("input[name='user.birthday']").val(data.user.birthday);
			form.render();
		} 
		find_userInfo_ByUserId(userId);
		
		//查找角色信息
		function find_roleName_list() {
			$.ajax({
				type: "get",
				url: "http://localhost:8080/ssmService/role/selectRoleName",
				async: true,
				"success": function(result) {
					if(result.resultCode == 0) {
						build_roleName_List(result);
					} else {
						layer.msg(result.message, {
							icon: 2,
							time: 1000
						});
					}

				}
			});
		}

		function build_roleName_List(result) {
			var roleNameList = result.data;
			$.each(roleNameList, function(index, item) {
				var roleCheckBox = $("<input type='checkbox' value='" + item.role_id + "' title='" + item.name + "'>");
				$(".roleList").append(roleCheckBox);
			});
			form.render();
		}
		find_roleName_list();
	});
}); 